package com.qf.controller;

import com.qf.pojo.reqVo.LiveUserReq;
import com.qf.pojo.resVo.BaseResult;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户的处理层
 */
@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 验证邮箱的接口
     */
    @RequestMapping(value = "/validataEmail",method = RequestMethod.POST)
    public BaseResult validataEmail(@RequestParam("email")String email){
        return userService.validataEmail(email);
    }

    /**
     * 验证登录名是否重复
     * @RequestBody LiveUserReq  接受的是一个Json对象
     * @return
     */
    @RequestMapping(value = "/validataloginName",method = RequestMethod.POST)
    public BaseResult validataloginName(@RequestBody LiveUserReq liveUserReq){
        return userService.validataloginName(liveUserReq);
    }

    /**
     * 通过邮箱获取验证码
     * @param email
     * @return
     */
    @GetMapping("/getCode")
    public BaseResult getCode(@RequestParam("email")String email){
            return userService.getCode(email);
    }

    /**
     * 用户注册
     * @param liveUserReq
     * @return
     */
    @PostMapping("/registry")
    public BaseResult registry(@RequestBody LiveUserReq liveUserReq){
        return userService.registry(liveUserReq);
    }

    /**
     * 用户登录接口
     */

    @RequestMapping("/login")
    public BaseResult login(@RequestBody LiveUserReq liveUserReq){
        return userService.login(liveUserReq);
    }

    /**
     * 通过token获取到用户信息
     */
    @RequestMapping("/findUserByToken")
    public BaseResult findUserByToken(HttpServletRequest request){
        return userService.findUserByToken(request);
    }
}
